package com.zx.BookSeaReader.greendao.gen;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.zx.BookSeaReader.greendao.entity.BookListCollect;
import com.zx.BookSeaReader.greendao.entity.SubscribeBean;

import com.zx.BookSeaReader.greendao.entity.Book;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "BOOK".
*/
public class BookDao extends AbstractDao<Book, String> {

    public static final String TABLENAME = "BOOK";

    /**
     * Properties of entity Book.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, String.class, "id", true, "ID");
        public final static Property Name = new Property(1, String.class, "name", false, "NAME");
        public final static Property ChapterUrl = new Property(2, String.class, "chapterUrl", false, "CHAPTER_URL");
        public final static Property ImgUrl = new Property(3, String.class, "imgUrl", false, "IMG_URL");
        public final static Property Desc = new Property(4, String.class, "desc", false, "DESC");
        public final static Property Author = new Property(5, String.class, "author", false, "AUTHOR");
        public final static Property Type = new Property(6, String.class, "type", false, "TYPE");
        public final static Property UpdateDate = new Property(7, String.class, "updateDate", false, "UPDATE_DATE");
        public final static Property NewestChapterId = new Property(8, String.class, "newestChapterId", false, "NEWEST_CHAPTER_ID");
        public final static Property NewestChapterTitle = new Property(9, String.class, "newestChapterTitle", false, "NEWEST_CHAPTER_TITLE");
        public final static Property NewestChapterUrl = new Property(10, String.class, "newestChapterUrl", false, "NEWEST_CHAPTER_URL");
        public final static Property HistoryChapterId = new Property(11, String.class, "historyChapterId", false, "HISTORY_CHAPTER_ID");
        public final static Property HisttoryChapterNum = new Property(12, int.class, "histtoryChapterNum", false, "HISTTORY_CHAPTER_NUM");
        public final static Property SortCode = new Property(13, int.class, "sortCode", false, "SORT_CODE");
        public final static Property NoReadNum = new Property(14, int.class, "noReadNum", false, "NO_READ_NUM");
        public final static Property ChapterTotalNum = new Property(15, int.class, "chapterTotalNum", false, "CHAPTER_TOTAL_NUM");
        public final static Property LastReadPosition = new Property(16, int.class, "lastReadPosition", false, "LAST_READ_POSITION");
        public final static Property Source = new Property(17, String.class, "source", false, "SOURCE");
        public final static Property LastRead = new Property(18, String.class, "lastRead", false, "LAST_READ");
        public final static Property IsLocal = new Property(19, boolean.class, "isLocal", false, "IS_LOCAL");
        public final static Property Recommend = new Property(20, int.class, "recommend", false, "RECOMMEND");
        public final static Property IsCollect = new Property(21, boolean.class, "isCollect", false, "IS_COLLECT");
    }

    private DaoSession daoSession;

    private Query<Book> bookListBean_BookListQuery;
    private Query<Book> userBean_BooksQuery;

    public BookDao(DaoConfig config) {
        super(config);
    }
    
    public BookDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = daoSession;
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"BOOK\" (" + //
                "\"ID\" TEXT PRIMARY KEY NOT NULL ," + // 0: id
                "\"NAME\" TEXT," + // 1: name
                "\"CHAPTER_URL\" TEXT," + // 2: chapterUrl
                "\"IMG_URL\" TEXT," + // 3: imgUrl
                "\"DESC\" TEXT," + // 4: desc
                "\"AUTHOR\" TEXT," + // 5: author
                "\"TYPE\" TEXT," + // 6: type
                "\"UPDATE_DATE\" TEXT," + // 7: updateDate
                "\"NEWEST_CHAPTER_ID\" TEXT," + // 8: newestChapterId
                "\"NEWEST_CHAPTER_TITLE\" TEXT," + // 9: newestChapterTitle
                "\"NEWEST_CHAPTER_URL\" TEXT," + // 10: newestChapterUrl
                "\"HISTORY_CHAPTER_ID\" TEXT," + // 11: historyChapterId
                "\"HISTTORY_CHAPTER_NUM\" INTEGER NOT NULL ," + // 12: histtoryChapterNum
                "\"SORT_CODE\" INTEGER NOT NULL ," + // 13: sortCode
                "\"NO_READ_NUM\" INTEGER NOT NULL ," + // 14: noReadNum
                "\"CHAPTER_TOTAL_NUM\" INTEGER NOT NULL ," + // 15: chapterTotalNum
                "\"LAST_READ_POSITION\" INTEGER NOT NULL ," + // 16: lastReadPosition
                "\"SOURCE\" TEXT," + // 17: source
                "\"LAST_READ\" TEXT," + // 18: lastRead
                "\"IS_LOCAL\" INTEGER NOT NULL ," + // 19: isLocal
                "\"RECOMMEND\" INTEGER NOT NULL ," + // 20: recommend
                "\"IS_COLLECT\" INTEGER NOT NULL );"); // 21: isCollect
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"BOOK\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, Book entity) {
        stmt.clearBindings();
 
        String id = entity.getId();
        if (id != null) {
            stmt.bindString(1, id);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(2, name);
        }
 
        String chapterUrl = entity.getChapterUrl();
        if (chapterUrl != null) {
            stmt.bindString(3, chapterUrl);
        }
 
        String imgUrl = entity.getImgUrl();
        if (imgUrl != null) {
            stmt.bindString(4, imgUrl);
        }
 
        String desc = entity.getDesc();
        if (desc != null) {
            stmt.bindString(5, desc);
        }
 
        String author = entity.getAuthor();
        if (author != null) {
            stmt.bindString(6, author);
        }
 
        String type = entity.getType();
        if (type != null) {
            stmt.bindString(7, type);
        }
 
        String updateDate = entity.getUpdateDate();
        if (updateDate != null) {
            stmt.bindString(8, updateDate);
        }
 
        String newestChapterId = entity.getNewestChapterId();
        if (newestChapterId != null) {
            stmt.bindString(9, newestChapterId);
        }
 
        String newestChapterTitle = entity.getNewestChapterTitle();
        if (newestChapterTitle != null) {
            stmt.bindString(10, newestChapterTitle);
        }
 
        String newestChapterUrl = entity.getNewestChapterUrl();
        if (newestChapterUrl != null) {
            stmt.bindString(11, newestChapterUrl);
        }
 
        String historyChapterId = entity.getHistoryChapterId();
        if (historyChapterId != null) {
            stmt.bindString(12, historyChapterId);
        }
        stmt.bindLong(13, entity.getHisttoryChapterNum());
        stmt.bindLong(14, entity.getSortCode());
        stmt.bindLong(15, entity.getNoReadNum());
        stmt.bindLong(16, entity.getChapterTotalNum());
        stmt.bindLong(17, entity.getLastReadPosition());
 
        String source = entity.getSource();
        if (source != null) {
            stmt.bindString(18, source);
        }
 
        String lastRead = entity.getLastRead();
        if (lastRead != null) {
            stmt.bindString(19, lastRead);
        }
        stmt.bindLong(20, entity.getIsLocal() ? 1L: 0L);
        stmt.bindLong(21, entity.getRecommend());
        stmt.bindLong(22, entity.getIsCollect() ? 1L: 0L);
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, Book entity) {
        stmt.clearBindings();
 
        String id = entity.getId();
        if (id != null) {
            stmt.bindString(1, id);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(2, name);
        }
 
        String chapterUrl = entity.getChapterUrl();
        if (chapterUrl != null) {
            stmt.bindString(3, chapterUrl);
        }
 
        String imgUrl = entity.getImgUrl();
        if (imgUrl != null) {
            stmt.bindString(4, imgUrl);
        }
 
        String desc = entity.getDesc();
        if (desc != null) {
            stmt.bindString(5, desc);
        }
 
        String author = entity.getAuthor();
        if (author != null) {
            stmt.bindString(6, author);
        }
 
        String type = entity.getType();
        if (type != null) {
            stmt.bindString(7, type);
        }
 
        String updateDate = entity.getUpdateDate();
        if (updateDate != null) {
            stmt.bindString(8, updateDate);
        }
 
        String newestChapterId = entity.getNewestChapterId();
        if (newestChapterId != null) {
            stmt.bindString(9, newestChapterId);
        }
 
        String newestChapterTitle = entity.getNewestChapterTitle();
        if (newestChapterTitle != null) {
            stmt.bindString(10, newestChapterTitle);
        }
 
        String newestChapterUrl = entity.getNewestChapterUrl();
        if (newestChapterUrl != null) {
            stmt.bindString(11, newestChapterUrl);
        }
 
        String historyChapterId = entity.getHistoryChapterId();
        if (historyChapterId != null) {
            stmt.bindString(12, historyChapterId);
        }
        stmt.bindLong(13, entity.getHisttoryChapterNum());
        stmt.bindLong(14, entity.getSortCode());
        stmt.bindLong(15, entity.getNoReadNum());
        stmt.bindLong(16, entity.getChapterTotalNum());
        stmt.bindLong(17, entity.getLastReadPosition());
 
        String source = entity.getSource();
        if (source != null) {
            stmt.bindString(18, source);
        }
 
        String lastRead = entity.getLastRead();
        if (lastRead != null) {
            stmt.bindString(19, lastRead);
        }
        stmt.bindLong(20, entity.getIsLocal() ? 1L: 0L);
        stmt.bindLong(21, entity.getRecommend());
        stmt.bindLong(22, entity.getIsCollect() ? 1L: 0L);
    }

    @Override
    protected final void attachEntity(Book entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
    }    

    @Override
    public Book readEntity(Cursor cursor, int offset) {
        Book entity = new Book( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // chapterUrl
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // imgUrl
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // desc
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // author
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // updateDate
            cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // newestChapterId
            cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // newestChapterTitle
            cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // newestChapterUrl
            cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // historyChapterId
            cursor.getInt(offset + 12), // histtoryChapterNum
            cursor.getInt(offset + 13), // sortCode
            cursor.getInt(offset + 14), // noReadNum
            cursor.getInt(offset + 15), // chapterTotalNum
            cursor.getInt(offset + 16), // lastReadPosition
            cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // source
            cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // lastRead
            cursor.getShort(offset + 19) != 0, // isLocal
            cursor.getInt(offset + 20), // recommend
            cursor.getShort(offset + 21) != 0 // isCollect
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, Book entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setChapterUrl(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setImgUrl(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setDesc(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setAuthor(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setUpdateDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setNewestChapterId(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
        entity.setNewestChapterTitle(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
        entity.setNewestChapterUrl(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10));
        entity.setHistoryChapterId(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11));
        entity.setHisttoryChapterNum(cursor.getInt(offset + 12));
        entity.setSortCode(cursor.getInt(offset + 13));
        entity.setNoReadNum(cursor.getInt(offset + 14));
        entity.setChapterTotalNum(cursor.getInt(offset + 15));
        entity.setLastReadPosition(cursor.getInt(offset + 16));
        entity.setSource(cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17));
        entity.setLastRead(cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18));
        entity.setIsLocal(cursor.getShort(offset + 19) != 0);
        entity.setRecommend(cursor.getInt(offset + 20));
        entity.setIsCollect(cursor.getShort(offset + 21) != 0);
     }
    
    @Override
    protected final String updateKeyAfterInsert(Book entity, long rowId) {
        return entity.getId();
    }
    
    @Override
    public String getKey(Book entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(Book entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "bookList" to-many relationship of BookListBean. */
    public List<Book> _queryBookListBean_BookList(Long bookListid) {
        synchronized (this) {
            if (bookListBean_BookListQuery == null) {
                QueryBuilder<Book> queryBuilder = queryBuilder();
                queryBuilder.join(BookListCollect.class, BookListCollectDao.Properties.Bookid)
                    .where(BookListCollectDao.Properties.BookListid.eq(bookListid));
                bookListBean_BookListQuery = queryBuilder.build();
            }
        }
        Query<Book> query = bookListBean_BookListQuery.forCurrentThread();
        query.setParameter(0, bookListid);
        return query.list();
    }

    /** Internal query to resolve the "books" to-many relationship of UserBean. */
    public List<Book> _queryUserBean_Books(Long userid) {
        synchronized (this) {
            if (userBean_BooksQuery == null) {
                QueryBuilder<Book> queryBuilder = queryBuilder();
                queryBuilder.join(SubscribeBean.class, SubscribeBeanDao.Properties.Bookid)
                    .where(SubscribeBeanDao.Properties.Userid.eq(userid));
                userBean_BooksQuery = queryBuilder.build();
            }
        }
        Query<Book> query = userBean_BooksQuery.forCurrentThread();
        query.setParameter(0, userid);
        return query.list();
    }

}
